$('input').iCheck({
  checkboxClass: 'icheckbox_minimal-blue',
  radioClass: 'iradio_minimal-blue'
});

$('#exampleModal').on('show.bs.modal', function (event) {

})
$('#create-bt').on('click', function (event) {
  $.ajax({
    type: "post",
    dataType: "json",
    url: "/"+$(this).attr("data-siteid")+"/post/create",
    data:{title:$("#title").val(),path:$("#path").val()},
    success: function (result) {
      if (result.code == 0) {
        $("#list").append("<tr><th scope=\"row\"><input type=\"checkbox\"></th><td><a href=\"/"+result.data.siteid+"/post/edit?path="+result.data.path+"\">"+result.data.title+"</a></td><td>-</td><td>-</td><td><a href=\""+result.data.path+"\" class=\"btn btn-default\">预览</a> <a class=\"delete-bt btn btn-default\" href=\"javascript:;\" data-siteid=\"{{ siteid }}\" data-path=\"\">删除</a></td></tr>");
        $("#title").val("")
        $("#path").val("")
        $("#exampleModal").modal('hide')
      } else {
        bootoast({
          message: '删除失败，'+result.msg,
          type: 'warning',
          position:'right-bottom',
          timeout:2
        });
      }
    },
    error : function() {
      bootoast({
        message: '异常',
        type: 'danger',
        position:'right-bottom',
        timeout:2
      });
    }
  });
  return false;
})

//删除
$('.delete-bt').on('click', function (event) {
  if (confirm("确定删除吗")) {
    $(this).parent().remove();
    $.ajax({
      type : "get",
      url: "/"+$(this).attr("data-siteid")+"/post/delete?path="+$(this).attr("data-path"),
      success: function (result) {
        if (result.code == 0) {
          bootoast({
              message: '删除成功',
              type: 'success',
              position:'right-bottom',
              timeout:2
          });
        } else {
          bootoast({
              message: '删除失败，'+result.msg,
              type: 'warning',
              position:'right-bottom',
              timeout:2
          });
        }
      },
      error : function() {
        bootoast({
          message: '异常',
          type: 'danger',
          position:'right-bottom',
          timeout:2
        });
      }
    });
  }
  return false;
})
